<?php

class AuthItemBehavior extends CBehavior
{
    public function getTypeName()
    {
        $type = $this->getOwner()->getType();
        if(CAuthItem::TYPE_ROLE == $type)
            return 'Role';
        else if(CAuthItem::TYPE_TASK == $type)
            return 'Task';
        else if(CAuthItem::TYPE_OPERATION == $type)
            return 'Operation';
        else
            throw new CException('Unknown type');
    }
    
    public function getTypeNameUrl()
    {
        return Yii::app()->getController()->createUrl('authItem/list', array('type'=>$this->getOwner()->getType()));
    }

    public function getTypeNameLink()
    {
        return CHtml::link(
            $this->getOwner()->getTypeName(),
            $this->getTypeNameUrl()
        );
    }
    
    public function getUpdateNameLink()
    {
        return CHtml::link(
            $this->getOwner()->getName(),
            $this->getUpdateUrl()
        );
    }
    
    public function getUpdateUrl()
    {
        return Yii::app()->getController()->createUrl('authItem/update', array('itemName'=>$this->getOwner()->getName()));
    }
    
    public function getDeleteUrl()
    {
        return Yii::app()->getController()->createUrl('authItem/delete', array('itemName'=>$this->getOwner()->getName()));
    }
}